<template>
<div style="height: 100%;position: fixed;width: 100%;">
  <el-row>
    <el-col style=" position: absolute; z-index: 1;" >
      <img src="beijing.jpg" style="width:100%;height: 100%" >
    </el-col>
  </el-row>

  <el-container style=" width: 400px;
  margin: 100px auto;
  padding: 20px;
  border: 1px solid #ccc;
  border-radius: 5px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.4);
  position: relative;z-index: 10;
  background-color: rgba(255, 255, 255, 0.5)">


    <el-main>

      <div class="login-container">
        <div class="login-logo" style="text-align: center;
  margin-bottom: 20px;">
          <img src="/avatar.png" alt="登录logo" style="width: 100px;height: 100px">
        </div>
        <h2>用户登录</h2>
        <el-form  label-width="80px">
          <el-form-item label="用户名">
            <el-input v-model="user.username" placeholder="请输入用户名"></el-input>
          </el-form-item>
          <el-form-item label="密码" >
            <el-input v-model="user.password" placeholder="请输入密码" type="password"></el-input>
          </el-form-item>
          <el-form-item align="center">
            <el-button type="primary" @click="login" style="margin-right: 40px">登录</el-button>
            <el-button >重置</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-main>
    <el-footer>
      <div class="login-footer">
        <p><b>青岛达外集团版权所有</b></p>
      </div>
    </el-footer>
  </el-container>
</div>
</template>

<script setup>
import {ref} from "vue";
import axios from "axios";
import {ElMessage} from "element-plus";
import router from "@/router";

const user = ref({
  username: '',
  password: ''
});
const login = ()=>{
  console.log(user.value);
  axios.post(BASE_URL+'/user/login',user.value)
      .then(response=>{
        if (response.data.code == 2000){
          ElMessage.success('登陆成功');
          router.push('/user');
          localStorage.setItem('user',JSON.stringify(response.data.data));
        }else {
          ElMessage.error(response.data.msg);
          user.value.username = '';
          user.value.password = '';
        }
      })
}
</script>

<style scoped>


.login-container h2 {
  text-align: center;
}

.el-form-item {
  margin-bottom: 15px;
}




</style>